﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit.Electric.Common;
using HYFamilyLibDataManager;

namespace HYRElectric.Dimension
{
	public partial class DlgEquipmentDim : System.Windows.Forms.Form
	{
		public DbFamily SelectDbFamily
		{
			get
			{
				return this.selectDbFamily;
			}
		}

		public DlgEquipmentDim(UIApplication uiApp, string elecTagType, string dlgText)
		{
			this.InitializeComponent();
			this.m_application = uiApp;
			this.m_document = null;
			this.m_lstElecTagType.Add(elecTagType);
			this.Text = dlgText;
			this.sysDB = null;
			this.selectDbFamily = null;
		}

		public DlgEquipmentDim(UIApplication uiApp, List<string> lstElecTagType, string dlgText)
		{
			this.InitializeComponent();
			this.m_application = uiApp;
			this.m_document = null;
			this.m_lstElecTagType = lstElecTagType;
			this.Text = dlgText;
			this.sysDB = null;
			this.selectDbFamily = null;
		}

		private void DlgEquipmentDim_Load(object sender, EventArgs e)
		{
			this.m_document = this.m_application.ActiveUIDocument.Document;
			this.cbxSymbol.Items.Clear();
			try
			{
				this.sysDB = FamilyLibDatabase.GetSqliteDB(SubjectType.System, this.m_application.Application.VersionNumber);
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			DbCategory dbCategory = this.sysDB.CategoryTable["电气标记"];
			foreach (string cName in this.m_lstElecTagType)
			{
				dbCategory = dbCategory[cName];
			}
			foreach (DbFamily item in dbCategory.GetAllFamilies(false, CheckType.All))
			{
				this.cbxSymbol.Items.Add(item);
			}
			if (this.cbxSymbol.Items.Count > 0)
			{
				this.cbxSymbol.SelectedIndex = 0;
			}
			this.selectDbFamily = (DbFamily)this.cbxSymbol.SelectedItem;
			this.pbView.Image = AssistFunc.ResizeImage((Bitmap)this.selectDbFamily.Image, 241, 80);
		}

		private void DlgEquipmentDim_MouseLeave(object sender, EventArgs e)
		{
			if (!base.ClientRectangle.Contains(base.PointToClient(Cursor.Position)))
			{
				WindowHelper.SendMessageToWndRevit();
				return;
			}
			base.Focus();
		}

		private void cbxSymbol_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.selectDbFamily = (DbFamily)this.cbxSymbol.SelectedItem;
			this.pbView.Image = AssistFunc.ResizeImage((Bitmap)this.selectDbFamily.Image, 241, 80);
		}

		private UIApplication m_application;

		private Document m_document;

		private List<string> m_lstElecTagType;

		private FamilyLibDatabase sysDB;

		private DbFamily selectDbFamily;
	}
}
